package com.cgbl.cg.ui.project

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.StringUtils
import com.cgbl.cg.BR
import com.cgbl.cg.R
import com.cgbl.cg.databinding.AppActivityReleaseProjectBinding
import com.cgbl.cg.view.ProjectFilterPop
import com.cgbl.cg.vm.project.ReleaseProjectViewModel
import com.lxj.xpopup.XPopup
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants

@Route(path = AppConstants.Router.PROJECT.A_RELEASE_PROJECT)
class ReleaseProjectActivity :
    GLBaseActivity<AppActivityReleaseProjectBinding, ReleaseProjectViewModel>() {

    override fun initVariableId(): Int = BR.viewModel

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_release_project

    override fun initComponents() {
        addSingleTitleBar(getString(R.string.app_en_tips_123))
        setViewData()
        viewModel.allType()
    }

    private fun setViewData() {
        SpanUtils.with(binding.tvPrompt)
            .append(StringUtils.getString(R.string.app_en_tips_120))
            .append(StringUtils.getString(R.string.app_en_tips_121))
            .setClickSpan(resources.getColor(R.color.app_286FFF), false) {

            }
            .create()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uc.showTypeDialog.observe(this) {
            val filterPop =
                ProjectFilterPop(this, viewModel.typeText.get() ?: "", viewModel.list)
            XPopup.Builder(this)
                .atView(binding.tvContent1)
                .asCustom(filterPop)
                .show()

            filterPop.setConfirmClickListener {
                filterPop.dismiss()
                viewModel.typeText.set(it.name)
                viewModel.typeId.set(it.id)
            }
        }
    }
}